$(function() {
	Power_Record.init();
})

/**
 * 会议权限--js
 * @author cl
 * @date 2019年4月4日
 */
var Power_Record = {
	_ID : null,
	_OBJ : null,
	mySelectCheck : null,
	userData : [],
	init : function() {
		var obj = GetRequest();
		Power_Record._ID = obj.id;
		Power_Record.loadUseData();
		Power_Record.initMySelect()
		Power_Record.findById(Power_Record._ID);
	},
	/**
	 * 加载可用用户
	 * 1、可以，0、不可用
	 */
	loadUseData : function() {
		$.ajax({
			url : "/crm/user/loadUserByIsUse", // 请求的url地址
			dataType : "json", // 返回格式为json
			async : false,// 请求是否异步，默认为异步，这也是ajax重要特性
			data : {
				isUse : 1
			}, // 参数值
			type : "post", // 请求方式
			success : function(data) {
				Power_Record.userData = data;
				//console.log(eval(data))
			},
			error : function() {
			}
		})
	},

	initMySelect : function() {
		var mySelect = $("#mySelect").mySelect({
			mult : true,//true为多选,false为单选
			option : Power_Record.userData,
			onChange : function(res) {//选择框值变化返回结果
				//console.log(res)
				//console.log(mySelect.getResultDatas());
			}
		});
		Power_Record.mySelectCheck = mySelect;

	},
	/**
	 * 根据id查询会议记录详情
	 */
	findById : function(id) {
		$.ajax({
			url : "/crm/meetingRecord/findById",
			dataType : "json",
			async : true,
			data : {
				id : id
			},
			type : "post",
			success : function(data) {
				//console.log(data)
				Power_Record._OBJ = data;
				$("#meetTitle").text(data.meetTitle);
				$("#meetSpeaker").text(data.meetSpeaker);
				$("#joinUserNames").text(data.joinUserNames);
				$("#meetTime").text(data.meetTime);
				$("#meetContent").text(data.meetContent);
				//附件加载及下载
				var fileParse = JSON.parse(data.meetFilePath);
				var html = '';
				$(fileParse).each(function(key, val) {
					html += '<li class="file_item filen"><span>' + val.name + '</span><a onclick="preview(\''+val.filePath+'\',1)">预览</a><a onclick="downloadServer(\'' + val.filePath + '\',1)">下载</a></li>';
				});
				$("#uploadAc").html(html);
				if (!isBlank(data.powerUserNames)) {
					$("#powerUserNames").text(data.powerUserNames);
				} else {
					$("#powerUserNames").parent().css("display", "none");
				}
				$("#createUserName").text(data.createUserName);
				$("#isStats").text(data.isStats == 0 ? "待审核可用" : data.isStats == 1 ? "审核通过" : "审核未通过");
				if (!isBlank(data.auditTime)) {
					$("#auditTime").text(data.auditTime);
				} else {
					$("#auditTime").parent().css("display", "none");
				}
				if (!isBlank(data.powerUserUuids)) {
					//展示添加的权限人员
					//var userNames=data.powerUserNames.split(",");
					var uuIds = data.powerUserUuids.split(",");
					Power_Record.mySelectCheck.setResult(uuIds);
				}

				$(".btn_ok").click(function() {
					var joinUserUuids = "";
					var joinUserNames = "";
					$.each(Power_Record.mySelectCheck.getResultDatas(), function(k, v) {
						joinUserUuids += ',' + v.value;
						joinUserNames += ',' + v.name;
					})
					joinUserUuids = joinUserUuids.substring(1);
					joinUserNames = joinUserNames.substring(1);
					Power_Record._OBJ.powerUserUuids = joinUserUuids;
					Power_Record._OBJ.powerUserNames = joinUserNames;
					//console.log(Power_Record._OBJ)
					var content = '编辑保存成功后，用户信息会发生改变，请确认操作？';
					layer.confirm(content, {
						icon : 3,
						title : '编辑确认'
					}, function(index) {
						layer.close(index);
						$.post("/crm/meetingRecord/save", Power_Record._OBJ, function(data) {
							if (data.status) {
								parent.refreshTabByIndex(0);
								//Meeting_Record_Add.allClear();
								layer.alert(data.info,function(){
									parent.closeCurPage();
								});
							}

						})
					});

				})
			},
			
			

			error : function() {
				layer.msg("系统错误！", {
					icon : 2,
					closeBtn : 0
				});
				;
			}
		});
	},
	
	removeUser : function(obj) {
		//console.log(obj);
		$(obj).parent().remove();

	}
}
